<table width="100%" border="0" cellpadding="0" cellspacing="0" class="tableform" >
<tbody>
  <tr<{if $is_rec_addr_edit != 'true' && $addr.addr_id}> style="display:none;"<{/if}>>
    <th><em class="font-red">*</em><{t}>收货地区：<{/t}></td>
    <td colspan=2>
      <span id="checkout-select-area"><{input type="region" id="shipping-area" name="delivery[ship_area]" app="ectools" vtype="area" value=$addr.area}></span>
    </td>
  </tr>
  <tr<{if $is_rec_addr_edit != 'true' && $addr.addr_id}> style="display:none;"<{/if}>>
    <th><em class="font-red">*</em><{t}>收货地址：<{/t}></td>
    <td>
    <input type='hidden' name='delivery[ship_addr_area]' value='' id='selected-area-hidden'/>
    <span id='selected-area' class='font-gray' title='<{t}>系统将拼接地区选择结果到收获地址<{/t}>'><{t}>[地区]<{/t}></span>
    <{input class="inputstyle" name="delivery[ship_addr]"   id="addr" vtype="required" value=$addr.addr size="50"}>
    </td>
  </tr>
  <tr<{if $is_rec_addr_edit != 'true' && $addr.addr_id}> style="display:none;"<{/if}>>
   <th><{if $site_checkout_zipcode_required_open=='true'}><em class="font-red">*</em><{/if}>
	<{t}>邮编：<{/t}></th>
    <td>
	<{if $site_checkout_zipcode_required_open=='true'}>
	<{input class="inputstyle" name="delivery[ship_zip]" size="15" id="zip" vtype="required" type="text" value=$addr.zipcode}>
	<{else}>
	<{input class="inputstyle" name="delivery[ship_zip]" size="15" id="zip"  type="text" value=$addr.zipcode}>
	<{/if}>
	</td>
  </tr>
  <tr<{if $is_rec_addr_edit != 'true' && $addr.addr_id}> style="display:none;"<{/if}>>
    <th><em class="font-red">*</em><{t}>收货人姓名：<{/t}></td>
    <td colspan=2><{input class="inputstyle" name="delivery[ship_name]" size="15" id="name" vtype="required"  type="text" value=$addr.name}></td>
  </tr>
  <{if !$address.member_id}>
  <tr<{if $is_rec_addr_edit != 'true' && $addr.addr_id}> style="display:none;"<{/if}>>
    <th><em class="font-red">*</em><{t}>Email：<{/t}></td>
    <td colspan=2><{input name="delivery[ship_email]" class="inputstyle" id="ship_email"  size="15" type="text" vtype="required&&email" value=$addr.email}></td>
  </tr>
  <{/if}>
  <tr<{if $is_rec_addr_edit != 'true' && $addr.addr_id}> style="display:none;"<{/if}>>
    <th>
      <em class="font-red">*</em><{t}>手机：<{/t}>
    </td>
    <td colspan=2>
     <{input class="inputstyle" name="delivery[ship_mobile]" size="15" type="text" id="mobile" value=$addr.phone.mobile}>
    </td>
  </tr>
  <tr<{if $is_rec_addr_edit != 'true' && $addr.addr_id}> style="display:none;"<{/if}>>
    <th>
      <{t}>固定电话：<{/t}>
    </td>
    <td colspan=2>
     <{input class="inputstyle" name="delivery[ship_tel]" size="15" type="text" id="tel" value=$addr.phone.telephone}>
	 <input type="hidden" vtype="mobile_or_phone" />
    </td>
  </tr>
  <{if $address.member_id}>
  <tr class="recsave"<{if $is_recsave_display != 'true'}> style="display:none;"<{/if}>>
    <th></th>
    <td colspan=2><a href="javascript:void(0);" _target="<{link app=b2c ctl="site_cart" act="purchase_save_addr"}>" title="saved addr" id="b2c-cart-checkout-save-recaddr"><{t}>保存收货地址<{/t}></a></td>
	<script>
		(function(){
			$('b2c-cart-checkout-save-recaddr').addEvent('click',function(e){
				var _target = $(e.target)||$(e);
				if ( !button_valiate.is_validate(_target) ) return false;
				var _action = _target.get('_target') ? _target.get('_target') : '';
				var _extends_args = $('order-create').getElement('input[name^=extends_args]') ? $('order-create').getElement('input[name^=extends_args]').value : null;
				if (_action){
					if ($('b2c-checkout-recaddr-list')){
						new Request.HTML({
							url:_action,
							update:'b2c-checkout-recaddr-list',
							method:'post',
							data:$('receiver').toQueryString() + '&member_id=' + document.getElement('input[name^=purchase[member_id]]').get('value') + '&extends_args=' + _extends_args,
							onComplete:function(res){
							}
						}).send();
					}else{
						new Request({
							url:_action,
							method:'post',
							data:$('receiver').toQueryString() + '&member_id=' + document.getElement('input[name^=purchase[member_id]]').get('value') + '&extends_args=' + _extends_args,
							onComplete:function(res){
								$('b2c-checkout-recaddr-list').innerHTML = res;
							}
						}).send();
					}
				}
			});
		})();
	</script>
  </tr>
  <{/if}>
  </tbody>
</table>
<{$selectArea}>
<script>
window.addEvent('domready',function(){

	document.getElement('#checkout-select-area input[name^=delivery[]').store('onselect',function(sel){

        /*if(!!sel.options[sel.selectedIndex].get('has_c')){
            $('shipping').set('html','<div class="valierror clearfix" style=" padding-left:20px"><{t}>请选择收货地区<{/t}></div>');
            $('selected-area').set('text','<{t}>[地区]<{/t}>').removeClass('font-black').addClass('font-gray');
        }*/

    });

    document.getElement('#checkout-select-area input[name^=delivery[]').store('lastsel',function(lastselect){
        var areaSels=$('checkout-select-area').getElements("select");
        var areaSelPrt=areaSels[0].getParent('*[package=mainland]');
        var selected=[];
        areaSels.each(function(s){
           var text = s[s.selectedIndex].text.trim().clean();
           if(['<{t}>北京<{/t}>','<{t}>天津<{/t}>','<{t}>上海<{/t}>','<{t}>重庆<{/t}>'].indexOf(text)>-1)return;
           selected.push(text);
        });
        var selectedV = selected.join('');
        $('selected-area').set('text',selectedV).removeClass('font-gray').addClass('font-black');
        $('selected-area-hidden').value =  selectedV;
		var _addr_node = $('addr');
		var _addr_value = _addr_node.value;
		var _replaced_value = _addr_node.value.replace(selectedV,'');

		var _input_radios = $$('input[name^=delivery[addr_id]]');

		if (_input_radios.length > 0){
			if (_replaced_value == '' && $('receiver').retrieve('b2c-cart-checkout-ship-addr') == 'true')
				_replaced_value = '.';
		}
        $('addr').set('value',_replaced_value);
   //     Order.setShippingFromArea(lastselect);
    });
    var areaSels=$$('#checkout-select-area select');

    var lastSel=areaSels[areaSels.length-1];

	if( lastSel && lastSel.get('value') != '' && lastSel.get('value') != '_NULL_' )
		lastSel.onchange(lastSel,lastSel.value,(areaSels.lengtd-1));

});
</script>
